package com.bbz.core.lambda.java8.Chapter_12_Date;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAdjuster;

/**
 * 实现了TemporalAdjuster接口，能够计算明天的日期，同时过滤掉周六和周日这些节假日
 */
public class NextWorkingDay implements TemporalAdjuster {
    @Override
    public Temporal adjustInto(Temporal temporal) {
        DayOfWeek dow=DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));
        int dayToAdd=1;
        if(dow==DayOfWeek.SATURDAY){dayToAdd=3;}//如果当天是周五，增加三天
        else if(dow == DayOfWeek.SATURDAY){dayToAdd=2;}//如果是周六增加两天。
        return temporal.plus(dayToAdd,ChronoUnit.DAYS);
    }
}
